class Solution {
public:
    int minSubArrayLen(int target, vector<int>& nums) {
        int left = 0;
        int right = 0;
        int ret = INT_MAX;
        int end = nums.size();
        int sum = 0;
        int flag = 0;
        for (right = 0; right < end; right++) {
            sum += nums[right];
            while (sum >= target) {
                flag = 1;
                ret = min(ret, right - left + 1);
                sum -= nums[left];
                ++left;
            }

        }
        if (flag) {
            return ret;
        }
        else {
            return 0;
        }

    }
};